﻿@{
    ViewBag.Title = "订单管理";
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    string wxOpenId = ViewBag.WXOpenId;
    int type = 1; //0 商城 2 集市
    string types = Request["type"] == null ? "1" : Request["type"].ToString();
    int.TryParse(types, out type);
}

<body class="page-order">
    @Html.Partial("_PMallHead")
    <input type="hidden" id="wxOpenId" value="@wxOpenId" />
    <!--header end-->
    <div class="mescroll" id="mescroll">
        <div class="mod-type mod-typeTab mb20">
            <ul id="status">
                <li class="cur" value="0">全部<i></i></li>
                <li value="1">待支付<i></i></li>
                <li value="2">待发货<i></i></li>
                <li value="3">待收货<i></i></li>
                <li value="4">已完成<i></i></li>
                <li value="5">已关闭<i></i></li>
            </ul>
        </div>
        <div class="mod-order">
            <ul id="order"></ul>
        </div>
    </div>

    <link href="~/Scripts/mescroll/mescroll.min.css" rel="stylesheet" />
    <script src="~/Scripts/mescroll/mescroll.min.js"></script>
    <script type="text/javascript">
            function isWxBrowser() {
            var result = false;
            //判断浏览器，在微信内打开，提示请在其他浏览器中打开
            var browser = {
                versions: function () {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {
                        //移动终端浏览器版本信息
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部,
                        WeiXin: u.match(/MicroMessenger/i) == "MicroMessenger" //是否为微信客户端
                    };
                }(),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            };
            if (browser.versions.mobile) {
                //判断是否是移动设备打开。browser代码在下面
                var ua = navigator.userAgent.toLowerCase();
                //获取判断用的对象
                if (ua.match(/MicroMessenger/i) == "micromessenger") { //微信中打开
                    return true;
                }
            }
            return result;
        }
        $(function () {
            var wxOpenId = $("#wxOpenId").val();
            if (isWxBrowser() == true && (wxOpenId == undefined || wxOpenId == "")) {
                window.location.href = '@Url.Action("GetWXOpenIdAuth", "CommonTokenMall")?returnUrl=@System.Web.HttpUtility.UrlEncode(Request.Url.ToString())';
            }
            if (isWxBrowser() == false && wxOpenId != undefined && wxOpenId != "") {
                $("#wxOpenId").val('');
                wxOpenId = "";
            }
        })

        function onBridgeReady(wcPayModel) {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest', {
                    "appId": wcPayModel.appid,
                    "timeStamp": wcPayModel.timestamp,
                    "nonceStr": wcPayModel.noncestr,
                    "package": wcPayModel.package,
                    "signType": "MD5",
                    "paySign": wcPayModel.paysign
                },
                function (res) {
                    if (res.err_msg == "get_brand_wcpay_request:ok") {// 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                        window.location.href = '/MyOrder/OrderList?type=1';
                    } else {
                        window.location.href = '/MyOrder/OrderList?type=1';
                    }
                }
            );
        }
    </script>
    <script type="text/javascript">
        $(function () {
            var status = 0;
            var mescroll = new MeScroll("mescroll", {
                down: {
                    auto: false,
                    callback: function (mescroll) {
                        mescroll.resetUpScroll(); //下拉刷新的回调,默认重置上拉加载列表为第一页
                    }
                },
                up: {
                    callback: getListData,
                    clearEmptyId: "order",
                    isBounce: false,
                    noMoreSize: 3,
                    htmlNodata: '<p class="upwarp-nodata">--没有更多数据了 --</p >',
                    empty: {
                        warpId: "order",
                        icon: "",
                        tip: "亲,没有您要找的订单~"

                    },
                    toTop: {
                        src: "/Content/css/tokenmall/img/toup.png",
                        html: " <img src='/Content/css/tokenmall/img/toup.png' />",
                        offset: 500
                    }
                }
            });

            function getListData(page) {
                $.ajax({
                    type: 'post',
                    url: '/MyOrder/_OrderList',
                    data: { page: page.num, size: page.size, order_status: status,type:@type },
                    success: function (response) {
                        var paged = $(response).siblings("page");
                        var rows = Number.parseInt(paged.attr("rows"));
                        var total = Number.parseInt(paged.attr("total_result"));
                        mescroll.endBySize(rows, total);
                        if (paged.length === 1) {
                            $("#order").append($(response));
                            $('#order page').remove();
                        }

                    },
                    error: function (e) {
                        //联网失败的回调,隐藏下拉刷新和上拉加载的状态
                        mescroll.endErr();
                    }
                });
            }

            $("ul#status").on("click", "li", function () {
                //只需要找到你点击的是哪个ul里面的就行
                $(this).addClass("cur").siblings().removeClass("cur");
                status = $(this).val();
                //重置列表数据
                mescroll.resetUpScroll();
                //隐藏回到顶部按钮
                mescroll.hideTopBtn();
            });

        });

    </script>
    <script type="text/javascript">
        $(function () {
            //防止后退
            var browser = {
                versions: function () {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {
                        //移动终端浏览器版本信息
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部,
                        WeiXin: u.match(/MicroMessenger/i) == "MicroMessenger" //是否为微信客户端
                    };
                }(),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            };

           //防止页面后退
            history.pushState(null, null, document.URL);
            window.onpopstate = function (e) {
                if (browser.versions.mobile) {
                    //判断是否是移动设备打开。browser代码在下面
                    var ua = navigator.userAgent.toLowerCase();
                    //获取判断用的对象
                    if (ua.match(/MicroMessenger/i) == "micromessenger") { //微信app
                        history.pushState(null, null, document.URL);
                        this.window.location.replace('@Url.Action("My", "User")');
                    } else {//非微信打开
                        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                            try {
                                if (isIOSAppNewBrowser != undefined && isIOSAppNewBrowser == true) {
                                    window.webkit.messageHandlers.gohome.postMessage(''); 
                                } else {
                                    gohome();
                                }
                            }
                            catch (ex) { history.pushState(null, null, document.URL); this.window.location.replace('@Url.Action("My", "User")');return; }
                        }
                        else if (/(Android)/i.test(navigator.userAgent)) {
                                try { androidfuntion.gohome(); }
                                catch (ex) { history.pushState(null, null, document.URL);this.window.location.replace('@Url.Action("My", "User")'); return;}
                        }
                    }
                } else {
                    //否则就是PC浏览器打开
                      history.pushState(null, null, document.URL);
                      this.window.location.replace('@Url.Action("My", "User")');
                }
            }
        })
    </script>

</body>
<style>
    .mescroll-totop img {
        max-width: 100%;
    }
</style>



